package com.example.test_system.api;

import com.example.test_system.model.*;
import com.example.test_system.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/question")
public class QuestionController {

    @Autowired
    QuestionService questionService;

    @ResponseBody
    @PostMapping("/addJudge")
    public Map<String, Object> addJudge(@RequestBody Judge req){
        questionService.addJudge(req);

        Map<String, Object> res = new HashMap<>();
        res.put("state", "ok");
        return res;
    }

    @ResponseBody
    @PostMapping("/addSingleChoice")
    public Map addSingleChoice(@RequestBody SingleChoice req){
        questionService.addSingleChoice(req);

        Map<String, Object> res = new HashMap<>();
        res.put("state", "ok");
        return res;
    }

    @ResponseBody
    @PostMapping("/addMultipleChoice")
    public Map addMultipleChoice(@RequestBody MultipleChoice req){
        questionService.addMultipleChoice(req);

        Map<String, Object> res = new HashMap<>();
        res.put("state", "ok");
        return res;
    }

    @ResponseBody
    @GetMapping("/listJudge")
    public Map listJudge(@RequestBody PageSearch pageSearch) {
        List<Judge> judges = questionService.listJudge(pageSearch.getPage(), pageSearch.getSize());

        Map<String, Object> res = new HashMap<>();
        res.put("state", "ok");
        res.put("data", judges);
        return res;
    }

    @ResponseBody
    @GetMapping("/listSingleChoice")
    public Map listSingleChoice(@RequestBody PageSearch pageSearch) {
        List<SingleChoice> SingleChoices = questionService.listSingleChoice(pageSearch.getPage(), pageSearch.getSize());

        Map<String, Object> res = new HashMap<>();
        res.put("state", "ok");
        res.put("data", SingleChoices);
        return res;
    }

    @ResponseBody
    @GetMapping("/listMultipleChoice")
    public Map listMultipleChoice(@RequestBody PageSearch pageSearch) {
        List<MultipleChoice> MultipleChoices = questionService.listMultipleChoice(pageSearch.getPage(), pageSearch.getSize());

        Map<String, Object> res = new HashMap<>();
        res.put("state", "ok");
        res.put("data", MultipleChoices);
        return res;
    }

    @ResponseBody
    @GetMapping("/deleteJudge")
    public Map deleteJudgeById(@RequestBody DeleteReq req){
        questionService.deleteJudgeById(req.getId());
        Map<String, Object> res = new HashMap<>();
        res.put("state", "ok");
        return res;
    }

    @ResponseBody
    @GetMapping("/deleteSingleChoice")
    public Map deleteSingleChoiceById(@RequestBody DeleteReq req){
        questionService.deleteSingleChoiceById(req.getId());
        Map<String, Object> res = new HashMap<>();
        res.put("state", "ok");
        return res;
    }

    @ResponseBody
    @GetMapping("/deleteMultipleChoice")
    public Map deleteMultipleChoiceById(@RequestBody DeleteReq req){
        questionService.deleteMultipleChoiceById(req.getId());
        Map<String, Object> res = new HashMap<>();
        res.put("state", "ok");
        return res;
    }
}
